package com.zhl.spark.core.rddtransform

import com.zhl.spark.core.BasicRdd

/**
 * @program: demos
 * @description: ${description}
 * @author: 刘振华
 * @create: 2020-12-01 10:56
 **/
object FlatMapRdd extends BasicRdd {
    def main(args: Array[String]): Unit = {
        test()
    }

    override def logic(): Unit = {
//        val rdd = sc.makeRDD(List(List(1,2),List(3,4)))
//        rdd.flatMap(list=>list).foreach(println)

//        val rdd = sc.makeRDD(List("hello world","hello scala"))
//        rdd.flatMap(line=>line.split(" ")).foreach(println)

        val rdd = sc.makeRDD(List(List(1,2),5,List(3,4)))
        rdd.flatMap(
            data => {
                data match {
                    case list:List[_] => list
                    case oth => List(oth)
                }
            }
        ).foreach(println)


    }
}
